package springboot.springboot06_ssmp.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import springboot.springboot06_ssmp.entity.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @author daiqiang
 * @date 2022/1/14-20:52
 */
@SpringBootTest
public class    IBookservicetest {
    @Autowired
    private IBookService bookService;
    @Test
    void testgetbyID(){
        System.out.println(bookService.getById((4)));
    }
    @Test
    void testSave() {
        Book book=new Book();
        book.setName("测试数据12313");
        book.setType("测试数据1321");
        book.setDescription("测试数据312321132");
        bookService.save(book);
    }
    @Test
    void testGetby2() {//条件查询---通用
        String name= "com";
        LambdaQueryWrapper<Book> lqw=new LambdaQueryWrapper<Book>();
        lqw.like(name!=null,Book::getName,name);
        //qw.equals("计算机基础");
        bookService.list(lqw);
    }
    @Test
    void testDelete() {
        bookService.removeById(6);
    }
    @Test//查询所有
    void testGetAll() {
        System.out.println(bookService.list());

    }
    @Test
    void testUpdate() {
        Book book=new Book();
        book.setId(4);
        book.setName("测试数据123");
        book.setType("测试数据123");
        book.setDescription( "SSFSFS");
        bookService.updateById(book);

    }
    @Test
    void testGetpage() {// 分页
        //SELECT * from ？？？limit ???  分页 拦截器
        IPage<Book> page=new Page(1,10);//
        // 第二页，两行
        bookService.page(page);
        System.out.println(page.getCurrent());
        System.out.println(page.getSize());
        System.out.println(page.getTotal());
        System.out.println(page.getRecords());

    }
}
